package org.wevil.repo.witcher3;

import org.wevil.entity.witcher3.Witcher3Menu;
import org.wevil.repo.BaseRepo;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface Witcher3MenuRepo extends BaseRepo<Witcher3Menu, Integer> {

    @Query("select count(pid) from Witcher3Menu where pid = ?1")
    Integer countByPid(Integer pid);

    @Query("from Witcher3Menu where id in ?1")
    List<Witcher3Menu> findByIdIn(List<Integer> ids);

    List<Witcher3Menu> findByPid(Integer pid);

    @Modifying
    @Query("update Witcher3Menu t set " +
            "t.name = case when :#{#entity.name} is null then t.name else :#{#entity.name} end, " +
            "t.url = case when :#{#entity.url} is null then t.url else :#{#entity.url} end, " +
            "t.pid = case when :#{#entity.pid} is null then t.pid else :#{#entity.pid} end, " +
            "t.sort = case when :#{#entity.sort} is null then t.sort else :#{#entity.sort} end, " +
            "t.icon = case when :#{#entity.icon} is null then t.icon else :#{#entity.icon} end " +
            "where t.id = :#{#entity.id}")
    int update(Witcher3Menu entity);


}
